package com.zycfc.zsf.boot.mybatis.generator.codegen.util;

import java.io.*;
import org.xml.sax.*;
import javax.xml.transform.stream.*;
import javax.xml.validation.*;
import javax.xml.transform.*;

public class XmlUtil
{
    public static String validXmlBySchema(final String xsdPath, final String xmlPath) {
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
        final File schemaFile = new File(xsdPath);
        Schema schema = null;
        try {
            schema = schemaFactory.newSchema(schemaFile);
        }
        catch (SAXException e) {
            e.printStackTrace();
        }
        final Validator validator = schema.newValidator();
        final Source source = new StreamSource(FileHelper.getInputStream(xmlPath));
        try {
            validator.validate(source);
        }
        catch (Exception ex) {
            return ex.getMessage();
        }
        return "";
    }
}
